{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "46b6d96e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "          品格        能力        资本        担保        环境\n",
      "品格  1.000000  0.726655  0.825342  0.676314  0.685563\n",
      "能力  0.726655  1.000000  0.929080  0.938382  0.841413\n",
      "资本  0.825342  0.929080  1.000000  0.883457  0.733482\n",
      "担保  0.676314  0.938382  0.883457  1.000000  0.762563\n",
      "环境  0.685563  0.841413  0.733482  0.762563  1.000000\n",
      "[0.84223701]\n"
     ]
    }
   ],
   "source": [
    "#1\n",
    "import pandas as pd\n",
    "from sklearn.decomposition import PCA\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "\n",
    "#2\n",
    "data = pd.read_excel('customer.xlsx')\n",
    "data.set_index('ID', inplace=True)\n",
    "# 相关系数矩阵\n",
    "print(data.corr())\n",
    "#3\n",
    "scaler=StandardScaler()\n",
    "scaler.fit(data)\n",
    "data=scaler.transform(data)\n",
    "#4\n",
    "pca = PCA(n_components=0.8)\n",
    "pca.fit(data)\n",
    "\n",
    "Y=pca.transform(data)\n",
    "gxl=pca.explained_variance_ratio_\n",
    "#5\n",
    "print(gxl)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "de3823a5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
